%%%-------------------------------------------------------------------
%%% File    : beta_memory_ets.erl
%%% Author  :  <vjache>
%%% Description : This is a simple implementation of beta memory 
%%% mainly for testing purpose.
%%%
%%% Created :  8 Jan 2010 by  <vjache>
%%%-------------------------------------------------------------------
-module(beta_memory_ets).

%% --------------------------------------------------------------------
%% Include files
%% --------------------------------------------------------------------
-include("../../include/erete.hrl").

%% API
-export([open/1,insert/4,delete/4,fetch_values/3]).

%%====================================================================
%% API
%%====================================================================
%%--------------------------------------------------------------------
%% Function: 
%% Description:
%%--------------------------------------------------------------------
open(Name) ->
	#mh{module=?MODULE,handle=ets:new(Name, [public,bag])}.

insert(Tab,Mp,K,V) ->
	Obj={{Mp,K},V},
	case ets:match_object(Tab, Obj) of
		[] ->
			ets:insert(Tab, Obj);
		[_] ->
			false
	end.
delete(Tab,Mp,K,V) ->
	Obj={{Mp,K},V},
	case ets:match_object(Tab, Obj) of
		[] ->
			false;
		[_] ->
			ets:delete_object(Tab, Obj)
	end.
fetch_values(Tab,Mp,K) ->
	iter_mapper:new(iter:from_list(ets:lookup(Tab, {Mp,K})),
					fun({{_Mp,_K},V})->
							V
					end).

%%====================================================================
%% Internal functions
%%====================================================================
